<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<link rel="stylesheet" href="css/listCommon.css" />
<link rel="stylesheet" href="css/evaluation.css" />
<link rel="stylesheet" href="css/bootstrap-3.3.7/css/bootstrap.min.css" />
<link rel="stylesheet" href="css/bootstrap-3.3.7/css/bootstrap-select.min.css" />
<link rel="stylesheet" href="css/register.css" />
<link rel="stylesheet" href="css/newListcommon.css" />
<link rel="stylesheet" href="css/maintenanceForm.css" />
<link rel="stylesheet" href="css/font-awesome-4.7.0/css/font-awesome.css" />
<style>
    .modal-backdrop {
        position: inherit;
    }
     .purchaseModal .modal-dialog, .biddingModal .modal-dialog{
         width: 600px;
         margin: 30px auto;
     }
    .delete .modal-dialog{
        width: 600px;
        margin: 30px auto;
    }
    .operate a{
        color:#666;
        display: inline-block;
        margin-right:15px;
        cursor: pointer;
        text-decoration: none;
    }
    .operate a i{
        display: inline-block;
        margin-right:5px;
    }
    .addNew table td, .addNew table th{
        padding:5px !important;
    }
</style>
<jsp:include page="../common/nav.jsp"></jsp:include>
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="purchaseOrder">
        <div class="formTitle">基本信息</div>
        <div class="trackInfomation">
            <div class="row">
                <div class="col-md-6">
                    <div class="form-group">
                        <span>*</span>
                        <label>标题：</label>
                        <input id="title" type="text" class="form-control" placeholder="请输入标题">
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-group">
                        <span>*</span>
                        <label>采购类型：</label>
                        <select id="procurementType" class="form-control" onchange="procurementTypeChange()">
                            <option value="">请选择采购类型</option>
                            <c:forEach items="${requestScope.procurementTypeMap}" var="map">
                                <option value="${map.key}">${map.value}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-group">
                        <span>*</span>
                        <label>开始交货日期：</label>
                        <input id="beginDate" type="date" class="form-control">
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-group">
                        <span>*</span>
                        <label>结束交货日期：</label>
                        <input id="endDate" type="date" class="form-control">
                    </div>
                </div>
            </div>
        </div>
        <div id="introduceTitle" class="formTitle" style="display: none">采购要求</div>
        <div id="introduceDiv" class="trackInfomation" style="display: none">
            <div class="row">
                <div class="col-md-6">
                    <div class="form-group">
                        <span>*</span>
                        <label>询价类型：</label>
                        <select id="inquiryType" class="form-control" onchange="inquiryTypeChange()">
                            <option value="">请选择询价类型</option>
                            <c:forEach items="${requestScope.inquiryTypeMap}" var="map">
                                <option value="${map.key}">${map.value}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-group">
                        <span>*</span>
                        <label>报价截止日期：</label>
                        <input id="quotationClosingDate" type="datetime-local" class="form-control">
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-group">
                        <span>*</span>
                        <label>交货期：</label>
                        下单后&nbsp;
                        <input id="day" type="number" class="form-control" style="width: 50%">
                        &nbsp;天内交货至指定地点
                    </div>
                </div>
            </div>
        </div>
        <div id="supplierRequirementTitle" class="formTitle" style="display: none">供应商要求</div>
        <div id="supplierRequirementDiv" class="trackInfomation" style="display: none">
            <div class="row">
                <div class="col-md-6">
                    <div class="form-group">
                        <span>*</span>
                        <label style="margin-right: 30px;">报价要求：</label>
                        <c:forEach items="${requestScope.quoteRequestMap}" var="map">
                            <input name="quoteRequest" type="checkbox" style="width: 4%" value="${map.key}" />${map.value}
                        </c:forEach>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-group">
                        <span>*</span>
                        <label>交易方式：</label>
                        <c:forEach items="${requestScope.tradingMannerMap}" var="map">
                            <input name="tradingManner" type="radio" style="width: 4%" value="${map.key}" onclick="tradingMannerChange('${map.key}')" />${map.value}
                        </c:forEach>
                    </div>
                </div>
                <div id="designatedSettlementDateDiv" class="col-md-6" style="display: none">
                    <div class="form-group">
                        <span>*</span>
                        <label>指定账期结算日：</label>
                        <c:forEach items="${requestScope.designatedSettlementDateMap}" var="map">
                            <input name="designatedSettlementDate" type="radio" style="width: 4%" value="${map.key}" onclick="designatedSettlementDateChange()" />${map.value}
                        </c:forEach>
                    </div>
                </div>
                <div id="settlementDateDiv" class="col-md-6" style="display: none">
                    <div class="form-group">
                        <span>*</span>
                        <label>账期结算日：</label>
                        <c:forEach items="${requestScope.settlementDateMap}" var="map">
                            <input name="settlementDate" type="radio" style="width: 4%" value="${map.key}" />${map.value}
                        </c:forEach>
                    </div>
                </div>
                <div id="paymentStageDiv" class="col-md-6" style="display: none">
                    <div class="form-group">
                        <span>*</span>
                        <label>阶段支付：</label>
                        <c:forEach items="${requestScope.paymentStageMap}" var="map">
                            <input name="paymentStage" type="radio" style="width: 4%" value="${map.key}" />${map.value}
                        </c:forEach>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-group">
                        <span>*</span>
                        <label>支付方式：</label>
                        <c:forEach items="${requestScope.paymentMap}" var="map">
                            <input name="payment" type="radio" style="width: 4%" value="${map.key}" checked />${map.value}
                        </c:forEach>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-group">
                        <span>*</span>
                        <label>发票要求：</label>
                        <c:forEach items="${requestScope.invoiceRequirementsMap}" var="map">
                            <input name="invoiceRequirements" type="radio" style="width: 4%" value="${map.key}" />${map.value}
                        </c:forEach>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-group">
                        <span >*</span>
                        <label style="margin-right: 30px;">证照要求：</label>
                        <c:forEach items="${requestScope.certificationRequirementsMap}" var="map">
                            <input name="certificationRequirements" type="checkbox" style="width: 4%" value="${map.key}" />${map.value}
                        </c:forEach>
                    </div>
                </div>
                <div class="col-md-12">
                    <div class="form-group">
                        <label>补充说明：</label>
                        <textarea id="remark" class="form-control fuyan" rows="3" placeholder="请输入补充说明" style="margin-left: 0;height:80px !important;">${requestScope.purchasingRequisition.remark}</textarea>
                    </div>
                </div>
            </div>
        </div>
        <div id="secrecyTitle" class="formTitle" style="display: none">询价方式及隐私设置</div>
        <div id="secrecyDiv" class="trackInfomation" style="display: none">
            <div class="row">
                <div class="col-md-6">
                    <div class="form-group">
                        <span>*</span>
                        <label>询价方式：</label>
                        <c:forEach items="${requestScope.bookBuildingMap}" var="map">
                            <input name="bookBuilding" type="radio" style="width: 4%" value="${map.key}" checked />${map.value}
                        </c:forEach>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-group">
                        <span>*</span>
                        <label>采购门户：</label>
                        <c:forEach items="${requestScope.procurementPortalMap}" var="map">
                            <input name="procurementPortal" type="radio" style="width: 4%" value="${map.key}" />${map.value}
                        </c:forEach>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-group">
                        <span>*</span>
                        <label>比价方式：</label>
                        <c:forEach items="${requestScope.priceComparisonWayMap}" var="map">
                            <input name="priceComparisonWay" type="radio" style="width: 4%" value="${map.key}" checked />${map.value}
                        </c:forEach>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-group">
                        <span>*</span>
                        <label>联系方式：</label>
                        <c:forEach items="${requestScope.contactWayMap}" var="map">
                            <input name="contactWay" type="radio" style="width: 4%" value="${map.key}" />${map.value}
                        </c:forEach>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-group">
                        <span>*</span>
                        <label>联系人：</label>
                        <input id="contacts" type="text" class="form-control" placeholder="请输入联系人">
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-group">
                        <span>*</span>
                        <label>联系电话：</label>
                        <input id="phone" type="text" class="form-control" placeholder="请输入联系电话">
                    </div>
                </div>
                <div id="provinceDiv" class="col-md-6" style="display: none">
                    <div class="form-group">
                        <span>*</span>
                        <label>省：</label>
                        <select class="form-control" name="province" id="province">
                            <option>--请选择--</option>
                        </select>
                    </div>
                </div>
                <div id="cityDiv" class="col-md-6" style="display: none">
                    <div class="form-group">
                        <span>*</span>
                        <label>市：</label>
                        <select class="form-control" name="city" id="city">
                            <option >--请选择--</option>
                        </select>
                    </div>
                </div>
                <div id="countyDiv" class="col-md-6" style="display: none">
                    <div class="form-group">
                        <span>*</span>
                        <label>县/区：</label>
                        <select class="form-control" name="county" id="county">
                            <option>--请选择--</option>
                        </select>
                    </div>
                </div>
                <div id="addressDiv" class="col-md-6" style="display: none">
                    <div class="form-group">
                        <span>*</span>
                        <label>收货地址：</label>
                        <input id="address" type="text" class="form-control" placeholder="请输入收货地址">
                    </div>
                </div>
            </div>
        </div>
        <div id="supplierTitle" class="formTitle" style="display: none">
            供应商信息
            <button type="button" class="btn" onclick="showSupplier()">添加供应商</button>
        </div>
        <div id="supplierDiv" class="tableWrap" style="display: none">
            <table class="table table-bordered">
                <thead id="supplierBody">
                    <tr>
                        <th width="5%">序号</th>
                        <th>所属公司</th>
                        <th>供应商名称</th>
                        <th>供应商类型</th>
                        <th>供应商电话</th>
                        <th>供应商地址</th>
                        <th>注册资本</th>
                        <th width="10%">操作</th>
                    </tr>
                    <tr id="supplierNothing">
                        <td colspan="8" style="color: #bbbbbb">无供应商信息</td>
                    </tr>
                </thead>
            </table>
        </div>
        <div class="formTitle">
            物资信息
            <button type="button" class="btn" onclick="showMaterial()">添加物资</button>
        </div>
        <div class="tableWrap">
            <table class="table table-bordered">
                <thead id="materialBody">
                    <tr>
                        <th width="5%">序号</th>
                        <th>采购方式</th>
                        <th>物料编码</th>
                        <th>品牌</th>
                        <th>物资名称</th>
                        <th>物类科目</th>
                        <th>型号</th>
                        <th>数量</th>
                        <th>单位</th>
                        <th width="10%">操作</th>
                    </tr>
                    <tr id="materialNothing">
                        <td colspan="12" style="color: #bbbbbb">无物资信息</td>
                    </tr>
                </thead>
            </table>
        </div>
        <div class="trackSubmit">
            <button type="button" onclick="save()">保存</button>
            <button type="button" onclick="window.location.href='web/inquiryList/getPageList'">返回</button>
        </div>
    </div>
</div>
<div id="headModal"></div>
<script src="css/bootstrap-3.3.7/js/jquery-2.1.4.min.js" type="text/javascript" charset="utf-8"></script>
<script src="css/bootstrap-3.3.7/js/bootstrap.js" type="text/javascript" charset="utf-8"></script>
<script src="css/bootstrap-3.3.7/js/bootstrap-select.min.js" type="text/javascript" charset="utf-8"></script>
<script src="css/bootstrap-3.3.7/js/address.js" type="text/javascript" charset="utf-8"></script>
<script>

    $(function () {
        let html = "";
        $("#county").append(html);
        $("#city").append(html);
        $.each(pdata,function(idx,item){
            if (parseInt(item.level) == 0) {
                html += "<option value="+item.code+" >"+ item.names +"</option> ";
            }
        });
        $("#province").append(html);

        $("#province").change(function(){
            $("#city option").remove();
            $("#county option").remove();
            let html = "<option value=''>--请选择--</option>";
            $("#county").append(html);
            if ($(this).val() == "") {
                return;
            }
            let code = $(this).find("option:selected").val().substring(0,2);
            $.each(pdata,function(idx,item){
                if (parseInt(item.level) == 1 && code == item.code.substring(0,2)) {
                    html +="<option value="+item.code+" >"+ item.names +"</option> ";
                }
            });
            $("#city ").append(html);
        });

        $("#city").change(function(){
            $("#county option").remove();
            let html = "<option value=''>--请选择--</option>";
            if ($(this).val() == "") {
                $("#county").append(html);
                return;
            }
            let code = $(this).find("option:selected").val().substring(0,4);
            $.each(pdata,function(idx,item){
                if (parseInt(item.level) == 2 && code == item.code.substring(0,4)) {
                    html +="<option value="+item.code+" >"+ item.names +"</option> ";
                }
            });
            $("#county").append(html);
        });
    });

    // 采购类型改变
    function procurementTypeChange() {
        switch ($('#procurementType').val()) {
            case "" :
                $('#introduceTitle').attr("style","display:none;");
                $('#introduceDiv').attr("style","display:none;");
                $('#supplierRequirementTitle').attr("style","display:none;");
                $('#supplierRequirementDiv').attr("style","display:none;");
                $('#secrecyTitle').attr("style","display:none;");
                $('#secrecyDiv').attr("style","display:none;");
                $('#supplierTitle').attr("style","display:none;");
                $('#supplierDiv').attr("style","display:none;");
                break;
            case "0" :
                $('#introduceTitle').attr("style","display:none;");
                $('#introduceDiv').attr("style","display:none;");
                $('#supplierRequirementTitle').attr("style","display:none;");
                $('#supplierRequirementDiv').attr("style","display:none;");
                $('#secrecyTitle').attr("style","display:none;");
                $('#secrecyDiv').attr("style","display:none;");
                $('#supplierTitle').attr("style","display:block;");
                $('#supplierDiv').attr("style","display:block;");
                break;
            case "1" :
                $('#introduceTitle').attr("style","display:block;");
                $('#introduceDiv').attr("style","display:block;");
                $('#supplierRequirementTitle').attr("style","display:block;");
                $('#supplierRequirementDiv').attr("style","display:block;");
                $('#secrecyTitle').attr("style","display:block;");
                $('#secrecyDiv').attr("style","display:block;");
                $('#supplierTitle').attr("style","display:none;");
                $('#supplierDiv').attr("style","display:none;");
                break;
        }
    }

    // 询价类型改变
    function inquiryTypeChange() {
        switch ($('#inquiryType').val()) {
            case "1" :
                $('#provinceDiv').attr("style","display:none;");
                $('#cityDiv').attr("style","display:none;");
                $('#countyDiv').attr("style","display:none;");
                $('#addressDiv').attr("style","display:none;");
                $('#supplierDiv').attr("style","display:block;");
                $('#supplierTitle').attr("style","display:block;");
                break;
            default:
                $('#provinceDiv').attr("style","display:block;");
                $('#cityDiv').attr("style","display:block;");
                $('#countyDiv').attr("style","display:block;");
                $('#addressDiv').attr("style","display:block;");
                $('#supplierDiv').attr("style","display:none;");
                $('#supplierTitle').attr("style","display:none;");
        }
    }

    // 指定账期结算日改变
    function designatedSettlementDateChange() {
        if ($('input[name = "designatedSettlementDate"]').filter(':checked').val() == "0") {
            $('#settlementDateDiv').attr("style","display:block;");
        } else {
            $('#settlementDateDiv').attr("style","display:none;");
        }
    }

    // 交易方式改变
    function tradingMannerChange(val) {
        switch (val) {
            case "0" :
                $('#designatedSettlementDateDiv').attr("style","display:block;");
                if ($('input[name = "designatedSettlementDate"]').filter(':checked').val() == "0") {
                    $('#settlementDateDiv').attr("style","display:block;");
                } else {
                    $('#settlementDateDiv').attr("style","display:none;");
                }
                $('#paymentStageDiv').attr("style","display:none;");
                break;
            default:
                $('#designatedSettlementDateDiv').attr("style","display:none;");
                $('#settlementDateDiv').attr("style","display:none;");
                $('#paymentStageDiv').attr("style","display:block;");
        }
    }

    var supplierIds = [];

    // 显示供应商弹框
    function showSupplier(data) {
        if (data == undefined) {
            data = {};
            data.page = 1;
            data.isBlacklist = "0";
            data.status = "Y";
            data.approveStatus = "APPROVE";
            data.notIn = supplierIds;
        }
        $('#selectPODiv').modal('hide');
        redragonJS.loading("ibox-content");
        $.ajax({
            type: "post",
            url: "web/mdVendor/getPageList",
            data: data,
            traditional: true,
            dataType: "html",
            async: false,
            cache: false,
            success: function(data){
                redragonJS.removeLoading("ibox-content");
                if(data!=""){
                    $("#headModal").html(data);
                    $('#selectPODiv').modal('show');
                    $(".modal-backdrop").remove();
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
                redragonJS.alert(textStatus);
            }
        });
    }

    // 删除供应商详情
    function delSupplier(index) {
        $("#supplierLine" + index).remove();
        if (index < supplierIds.length) {
            for (var i = index + 1; i <= supplierIds.length; i ++) {
                let num = i - 1;
                $("#supplierLine" + i).attr("id", "supplierLine" + num);
                $("#supplierNo" + i).text(num).attr("id", "supplierNo" + num);
                $("#supplierId" + i).attr("id", "supplierId" + num);
                $("#supplierCompany" + i).attr("id", "supplierCompany" + num);
                $("#supplierName" + i).attr("id", "supplierName" + num);
                $("#supplierType" + i).attr("id", "supplierType" + num);
                $("#supplierTel" + i).attr("id", "supplierTel" + num);
                $("#supplierAddress" + i).attr("id", "supplierAddress" + num);
                $("#supplierRegisteCapital" + i).attr("id", "supplierRegisteCapital" + num);
                $("#supplierOperation" + i).attr("id", "supplierOperation" + num);
                $("#supplierdel" + i).attr("id", "supplierdel" + num).attr("onclick", "delSupplier(" + num + ")");
            }
        }
        supplierIds.splice(index - 1, 1);
        if (supplierIds.length == 0) {
            $("#supplierBody").append(
                '<tr id="supplierNothing">' +
                    '<td colspan="8" style="color: #bbbbbb">无供应商信息</td>' +
                '</tr>'
            );
        }
    }

    var materialIds = [];
    var materialSise = 0;

    // 显示物资弹框
    function showMaterial(data) {
        if (data == undefined) {
            data = {};
            data.page = 1;
            data.notIn = materialIds;
        }
        $('#selectPODiv').modal('hide');
        redragonJS.loading("ibox-content");
        $.ajax({
            type: "post",
            url: "web/purchasingRequisitionDetail/getSubPageList",
            data: data,
            traditional: true,
            dataType: "html",
            async: false,
            cache: false,
            success: function(data){
                redragonJS.removeLoading("ibox-content");
                if(data!=""){
                    $("#headModal").html(data);
                    $('#selectPODiv').modal('show');
                    $(".modal-backdrop").remove();
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
                redragonJS.alert(textStatus);
            }
        });
    }

    // 删除物资详情
    function delMaterial(index) {
        let ids = $("#materialDetailId" + index).text().split(",");
        $("#materialLine" + index).remove();
        if (index < materialIds.length) {
            for (var i = index + 1; i <= materialIds.length; i ++) {
                let num = i - 1;
                $("#materialLine" + i).attr("id", "materialLine" + num);
                $("#materialNo" + i).text(num).attr("id", "materialNo" + num);
                $("#materialDetailId" + i).attr("id", "materialDetailId" + num);
                $("#materialId" + i).attr("id", "materialId" + num);
                $("#lineType" + i).attr("id", "lineType" + num);
                $("#lineTypeText" + i).attr("id", "lineTypeText" + num);
                $("#materialCode" + i).attr("id", "materialCode" + num);
                $("#materialBrand" + i).attr("id", "materialBrand" + num);
                $("#materialName" + i).attr("id", "materialName" + num);
                $("#materialType" + i).attr("id", "materialType" + num);
                $("#materialModelNumberText" + i).attr("id", "materialModelNumberText" + num);
                $("#materialNumber" + i).attr("id", "materialNumber" + num);
                $("#materialUnit" + i).attr("id", "materialUnit" + num);
                $("#materialOperation" + i).attr("id", "materialOperation" + num);
                $("#materialdel" + i).attr("id", "materialdel" + num).attr("onclick", "delMaterial(" + num + ")");
            }
        }
        for (let i = 0; i < ids.length; i ++) {
            materialIds.splice(materialIds.indexOf(ids[i]), 1);
        }
        if (-- materialSise == 0) {
            $("#materialBody").append(
                '<tr id="materialNothing">' +
                    '<td colspan="12" style="color: #bbbbbb">无物资信息</td>' +
                '</tr>'
            );
        }
    }

    // 保存
    function save() {
        if ($("#day").val() != "") {
            if ($("#day").val() % 1 != 0) {
                redragonJS.alert("交货期必须为整数!");
                return;
            }
            if ($("#day").val() < 1) {
                redragonJS.alert("交货期必须大于0!");
                return;
            }
        }
        $.ajax({
            type:'post',
            url : "web/inquiryList/save",
            contentType : "application/json",
            data : JSON.stringify(getSubmitInfo()),
            dataType : 'json',
            async : true,
            success : function(data) {
                if(data.code == 1) {
                    redragonJS.alert("操作成功!");
                    setTimeout(function(){
                        window.location.href='web/inquiryList/getPageList'
                    },1000);
                } else {
                    redragonJS.alert(data.msg);
                }
            }
        });
    }

    // 获取提交数据
    function getSubmitInfo() {
        let data = {};
        data.title = $("#title").val();
        data.procurementType = $("#procurementType").val();
        data.inquiryType = $("#inquiryType").val();
        data.quotationClosingDate = $("#quotationClosingDate").val();
        data.beginDate = $("#beginDate").val();
        data.endDate = $("#endDate").val();
        data.day = $("#day").val();
        data.quoteRequest = parseArray('0');
        data.tradingManner = $('input[name = "tradingManner"]').filter(':checked').val();
        data.designatedSettlementDate = $('input[name = "designatedSettlementDate"]').filter(':checked').val();
        data.settlementDate = $('input[name = "settlementDate"]').filter(':checked').val();
        data.paymentStage = $('input[name = "paymentStage"]').filter(':checked').val();
        data.payment = $('input[name = "payment"]').filter(':checked').val();
        data.invoiceRequirements = $('input[name = "invoiceRequirements"]').filter(':checked').val();
        data.certificationRequirements = parseArray('1');
        data.remark = $("#remark").val();
        data.bookBuilding = $('input[name = "bookBuilding"]').filter(':checked').val();
        data.procurementPortal = $('input[name = "procurementPortal"]').filter(':checked').val();
        data.priceComparisonWay = $('input[name = "priceComparisonWay"]').filter(':checked').val();
        data.contactWay = $('input[name = "contactWay"]').filter(':checked').val();
        data.contacts = $("#contacts").val();
        data.phone = $("#phone").val();
        data.province = $("#province").val();
        data.city = $("#city").val();
        data.county = $("#county").val();
        data.address = $("#address").val();
        let suppliers = [];
        for(let i = 1; i <= supplierIds.length; i ++){
            let sub = {};
            sub.supplierId = $("#supplierId" + i).text();
            sub.company = $("#supplierCompany" + i).text();
            sub.name = $("#supplierName" + i).text();
            sub.type = $("#supplierType" + i).text();
            sub.tel = $("#supplierTel" + i).text();
            sub.address = $("#supplierAddress" + i).text();
            sub.registeCapital = $("#supplierRegisteCapital" + i).text();
            suppliers.push(sub);
        }
        data.supplierList = suppliers;
        let materials = [];
        for(let i = 1; i <= materialSise; i ++) {
            let sub = {};
            sub.detailId = $("#materialDetailId" + i).text();
            sub.materialId = $("#materialId" + i).text();
            sub.materialCode = $("#materialCode" + i).text();
            sub.lineType = $("#lineType" + i).text();
            sub.materialBrand = $("#materialBrand" + i).text();
            sub.materialName = $("#materialName" + i).text();
            sub.materialType = $("#materialType" + i).text();
            sub.materialModel = $("#materialModelNumberText" + i).text();
            sub.materialUnit = $("#materialUnit" + i).text();
            sub.materialNumber = $("#materialNumber" + i).text();
            materials.push(sub);
        }
        data.materialList = materials;
        return data;
    }

    // 添加详情
    function appendHtml(appendId, removeId, html) {
        $("#" + removeId).remove();
        $("#" + appendId).append(html);
    }

    // 解析数组
    function parseArray(type) {
        let arr = [];
        if (type == '0') {
            $('input:checkbox[name=quoteRequest]:checked').each(function (i) {
                arr.push($(this).val());
            });
        } else {
            $('input:checkbox[name=certificationRequirements]:checked').each(function (i) {
                arr.push($(this).val());
            });
        }
        if (arr.length == 0) {
            return "";
        } else if (arr.length == 1) {
            return arr[0] + "";
        } else {
            let result = arr[0];
            for (let i = 1; i < arr.length; i ++) {
                result += "," + arr[i];
            }
            return result;
        }
    }
</script>